# -*- coding: utf-8 -*-


try:
    from docutils.core import publish_parts
    try:
        from board.markup import rst_directives
    except ImportError:
        # No Pygments installed
        pass
    def render_rest(text, **docutils_options):
        parts = publish_parts(source=text, writer_name='html4css1',
            settings_overrides=docutils_settings)
        return parts['html_body']
except ImportError:
    def render_rest(text, **kw):
        return text


try:
    from markdown import Markdown
    try:
        from board.markup.markdown_processors import CodeBlockPreprocessor
        use_pygments = True
    except ImportError:
        # No Pygments installed
        use_pygments = False
    def render_markdown(text, **markdown_options):
        md = Markdown(extensions=['extra'], **markdown_options)
        if use_pygments:
            md.textPreprocessors.insert(0, CodeBlockPreprocessor)
        html = md.convert(text)
        return html
except ImportError:
    def render_markdown(text, **kw):
        return text
